//
//  RegisterViewController.m
//  PT
//
//  Created by jarze on 15/6/8.
//  Copyright (c) 2015年 jarze. All rights reserved.
//

#import "RegisterViewController.h"
#import "MBProgressHUD+NJ.h"

//#define FilePath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject ] stringByAppendingPathComponent:@"contacts.plist"]

@interface RegisterViewController ()
//@property (nonatomic, strong) NSMutableArray *contatcs;

@end

@implementation RegisterViewController
//- (NSMutableArray *)contatcs
//{
//    if (_contatcs == nil) {
//        
//        // 从归档文件中读取数据
//        _contatcs = [NSKeyedUnarchiver unarchiveObjectWithFile:FilePath];
//        
//        if (_contatcs == nil) {
//            
//            _contatcs = [NSMutableArray array];
//            
//        }
//    }
//    return _contatcs;
//}





- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.backBarButtonItem = Nil;
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    
    [center addObserver:self selector:@selector(textChangeField) name:UITextFieldTextDidChangeNotification object:self.account];
    
    [center addObserver:self selector:@selector(textChangeField) name:UITextFieldTextDidChangeNotification object:self.password];
    
    [center addObserver:self selector:@selector(textChangeField) name:UITextFieldTextDidChangeNotification object:self.name];
    
 
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)textChangeField
{
    
    self.registerBtn.enabled = [NSString checkUserEmail: self.account.text] && [NSString checkPassword:self.password.text] && [NSString checkUserName:self.name.text];
    self.Tpassword.hidden = [NSString checkPassword:self.password.text];
    self.Tname.hidden = [NSString checkUserName:self.name.text];
    self.Taccount.hidden = [NSString checkUserEmail:self.account.text];


}

- (void)viewDidAppear:(BOOL)animated
{
    // 主动召唤键盘
    [self.name becomeFirstResponder];
    
}


- (IBAction)registerBtn:(id)sender {
//    // 5.保存用户数据
//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//    [defaults setObject:self.account.text forKey:@"account"];
//    [defaults setObject:self.password.text forKey:@"password"];
//    [defaults setObject:self.name.text forKey:@"name"];
//    [defaults synchronize];
//   // NSLog(@"%", defaults);
    
    
    //添加蒙版禁止用户操作, 并且提示用户正在登录
    [MBProgressHUD showMessage:@"正在为您注册新账号...."];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUD];
    // 跳转到免费领取界面(手动执行segue)
        [self performSegueWithIdentifier:@"registerToReceive" sender:nil];

    });
}


@end
